Skip to content

Method: IntegerComparisonTerm(int, int)

1: /*
2: * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Public License v. 2.0, which is available at
6: * http://www.eclipse.org/legal/epl-2.0.
7: *
8: * This Source Code may also be made available under the following Secondary
9: * Licenses when the conditions for such availability set forth in the
10: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11: * version 2 with the GNU Classpath Exception, which is available at
12: * https://www.gnu.org/software/classpath/license.html.
13: *
14: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15: */
16:
17: package jakarta.mail.search;
18:
19: /**
20: * This class implements comparisons for integers.
21: *
22: * @author Bill Shannon
23: * @author John Mani
24: */
25: public abstract class IntegerComparisonTerm extends ComparisonTerm {
26: /**
27: * The number.
28: *
29: * @serial
30: */
31: protected int number;
32:
33: private static final long serialVersionUID = -6963571240154302484L;
34:
35: protected IntegerComparisonTerm(int comparison, int number) {
36:         this.comparison = comparison;
37:         this.number = number;
38: }
39:
40: /**
41: * Return the number to compare with.
42: *
43: * @return        the number
44: */
45: public int getNumber() {
46:         return number;
47: }
48:
49: /**
50: * Return the type of comparison.
51: *
52: * @return        the comparison type
53: */
54: public int getComparison() {
55:         return comparison;
56: }
57:
58: protected boolean match(int i) {
59:         switch (comparison) {
60:          case LE:
61:                 return i <= number;
62:          case LT:
63:                 return i < number;
64:          case EQ:
65:                 return i == number;
66:          case NE:
67:                 return i != number;
68:          case GT:
69:                 return i > number;
70:          case GE:
71:                 return i >= number;
72:          default:
73:                 return false;
74:         }
75: }
76:
77: /**
78: * Equality comparison.
79: */
80: @Override
81: public boolean equals(Object obj) {
82:         if (!(obj instanceof IntegerComparisonTerm))
83:          return false;
84:         IntegerComparisonTerm ict = (IntegerComparisonTerm)obj;
85:         return ict.number == this.number && super.equals(obj);
86: }
87:
88: /**
89: * Compute a hashCode for this object.
90: */
91: @Override
92: public int hashCode() {
93:         return number + super.hashCode();
94: }
95: }